package book_mianshizhinan.test1_2;

import java.util.Stack;

/**
 * ����ջʵ�ֶ���
 * @author Frank
 *
 */
public class TwoStackQueue {
	
	Stack <Integer> stackPush;
	Stack <Integer> stackPop;
	
	TwoStackQueue() {
		stackPush = new Stack<Integer>();
		stackPop = new Stack<Integer>();
	}
	
	void add (int newNum){
		
		stackPush.push(newNum);
		if(!stackPop.empty()){
			stackPop.clear();
		}
	}
	
	int poll(){
		if(stackPop.empty() && stackPush.empty()){
			throw new RuntimeException("Empty");
		}else if(stackPop.empty()){
			while(stackPush.empty()){
				stackPop.push(stackPush.pop());
			}
		}
		return stackPop.pop();
		
	}
	
	int peek(){
		
		if(stackPop.empty() && stackPush.empty()){
			throw new RuntimeException("Empty");
		}else if(stackPop.empty()){
			while(stackPush.empty()){
				stackPop.push(stackPush.pop());
			}
		}
		return stackPop.peek();
	}

}
